var fs = require("fs");
var Q = require("q");

//自定义封装函数为promise
var fsReadFile_defer = function(file, encoding){
    var defer = Q.defer();
    fs.readFile(file, encoding, function(err, result){
        if(err){
            defer.reject("----err flag1---" + err.toString());
        }
        defer.resolve(result);
    });

    return defer.promise;
}

fsReadFile_defer("test.txt").then(function(result){
    console.log("----flag3-----" + result);

},                                function(err){
    console.log("--------err flag2------" + err.toString());
});

